using System;
using System.Collections.Generic;
using System.Text;
using Barrage.Elements;
using SlimDX;
using Spacedash.Logic.Scenario;
using Barrage.Global;

namespace Spacedash.Game.Cameras
{
    class CreditsCamera:Camera
    {
        Random random;
        Vector3 position;
        Scenario scenario;
        
        public override Vector3 Position
        {
            get { return position; }
        }

        Vector2 viewportSize;
        Vector2 scenarioPos;
        //float fov = (float)System.Math.PI / 2;

        void UpdateProjection()
        {
            projection = Matrix.PerspectiveOffCenterLH(-0.8f, 1.2f, -0.5f, 0.5f, 1, 50000);
                //.PerspectiveFovLH(fov, viewportSize.X / (float)viewportSize.Y, 1, 15000);
        }

        public CreditsCamera(Scenario scenario,Vector2 viewportSize)
        {
            this.scenario = scenario;
            this.viewportSize = viewportSize;
            random = new Random();
            UpdateProjection();
        }

        protected override void DoUpdate()
        {
            scenarioPos.Y += 60f * Timer.DefaultTimer.LastIntervalSeconds;

            float baseYHeight = 400;
            float baseZOffset = 0;
            float targetZOffset = 150;

            Vector3 normal;
            Vector3 tangent;
            Barrage.Motion scenarioMotion = scenario.getItemMotion(scenarioPos,out normal,out tangent);
           
            Vector3 offset1 = new Vector3(0, normal.Y * baseYHeight - normal.Z * baseZOffset, normal.Y * baseZOffset + normal.Z * baseYHeight);
            Vector3 offset2 = new Vector3(0, -normal.Z * targetZOffset, normal.Y * targetZOffset);

            position = (scenarioMotion.Translation + offset1);//GameMath.Damping(position,(cameraTarget+offset1),new Vector3(0.1f,0.001f,0.001f),Timer.DefaultTimer.LastIntervalSeconds);
            
            //motion.Matrix = Matrix.LookAtLH(position, scenarioMotion.Translation + offset2, new Vector3(0, normal.Y, normal.Z));
            motion.Matrix = Matrix.LookAtLH(position, scenarioMotion.Translation + offset2, new Vector3(-1.25f, normal.Y, normal.Z));

            //fov = GameMath.Damping(fov, MIN_FOV + target.Ship.Speed / 15.0f, 0.25f, Timer.DefaultTimer.LastIntervalSeconds);
            //fov = Math.Min(fov, MAX_FOV);
            UpdateProjection();

            
            base.DoUpdate();
        }

    }
}
